<?php
if ( !function_exists('alert') ) :
function alert($msg) {
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
  echo "<script language = 'javascript'>";
  echo "alert('$msg')";
  echo "</script>";
}
endif;

if ( !function_exists('top_redirect') ) :
function top_redirect($url) {
  echo "<script language = 'javascript'>";
  echo "window.top.location.href='$url';";
  echo "</script>";
}
endif;

if ( !function_exists('redirect') ) :
/**
 * Redirects to another page.
 */
function redirect($url, $d = 0, $msg = "") {
    echo "<html><head>\n";
    echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>\n";
    echo "<meta http-equiv='refresh' content='$d; URL=$url'>\n";
    echo "</head><body>$msg</body></html>\n";
    exit;
}
endif;

if ( !function_exists('_php') ) :
/**
 * Get Templete file name ex. index.html will get index.php
 */
function _php($path) {
	$path_parts = pathinfo($path);
	return $path_parts['dirname'] ."/". $path_parts['filename'] . ".php";
}
endif;

if ( !function_exists('_html') ) :
/**
 * Get Templete file name ex. index.php will get index.html
 */
function _html($path) {
	$path_parts = pathinfo($path);
	return $path_parts['dirname'] ."/". $path_parts['filename'] . ".html";
}
endif;

function pagenavi($num, $p, $list_per_page = 12, $arg = ""){

	global $item_start, $item_end, $cid;

    if($p == null) $p = 1;
    elseif($p < 1) $p = 1;
    elseif($p > ceil($num / $list_per_page))
        $p = ceil($num / $list_per_page);

    $item_start = ($p-1) * $list_per_page;
    $item_end = $start + $list_per_page;

	$pagenavi_html .= "<ul class='page-list'>\n";
	for($i = 1; $i <= ceil($num / $list_per_page); $i++){
		if($i == $p){
			$pagenavi_html .= "<li><a href = '?p=$i&$arg' class = 'active'>".$i."</a></li>\n";
		}else{
			$pagenavi_html .= "<li><a href = '?p=$i&$arg'>".$i."</a></li>\n";
		}
	}
	$pagenavi_html .= "</ul>\n";

	return $pagenavi_html;
}

if ( !function_exists('upload') ) :

function upload($file, $savefile = ""){

    if ($_FILES[$file]['name'] != ''){

        if ($_FILES[$file]['error'] > 0) {
            echo 'Problem: ';
            switch ($_FILES[$file]['error']){
                case 1:
                    echo 'File exceeded upload_max_filesize';
                    break;
                case 2:
                    echo 'File exceeded max_file_size';
                    echo 'please resize picture to less than 600K then try again';
                    break;
                case 3:
                    echo 'File only partially uploaded';
                    break;
                case 4:
                    echo 'No file uploaded';
                    break;
            }
            return false;
        }

        if (is_uploaded_file($_FILES[$file]['tmp_name'])){

            if($savefile == ""){
                $path_info = pathinfo($_FILES[$file]['name']);
                $filename = time();
                $savefile = UPLOAD. $filename .".".$path_info['extension'];
                $destination = URL."upload/".$filename .".".$path_info['extension'];

                if(file_exists($savefile)){
                    $filename = time()+1;
                    $savefile = UPLOAD. $filename .".".$path_info['extension'];
                    $destination = URL."upload/". $filename .".".$path_info['extension'];
                }
            }

            if (!move_uploaded_file($_FILES[$file]['tmp_name'], $savefile)){
                echo 'Problem: Could not move file to destination directory';
                return false;
            }else{

                return array($destination, $savefile);
            }
        }else{
            echo 'Problem: Possible file upload attack. Filename: '.$file;
            return false;
        }
        chmod($savefile, 0755);
    }

    return false;
}

endif;

if ( !function_exists('jquery') ) :
function jquery(){
	echo "<script type='text/javascript' src='".URL."script/jquery-latest.min.js'></script>"."\n";
}
endif;

if ( !function_exists('tiny_mce') ) :
function tiny_mce($init = 'init.js'){
	echo '<script src="'.URL.'script/tinymce/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'script/tinymce/'.$init.'" type="text/javascript"></script>'."\n";
}
endif;

if ( !function_exists('jquery_validate') ) :
function jquery_validate($lan = 'en'){
	echo '<script src="'.URL.'script/validate/jquery.validationEngine-'.$lan.'.js" type="text/javascript" charset="utf-8"></script>'."\n";
	echo '<script src="'.URL.'script/validate/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>'."\n";
	echo '<link rel="stylesheet" href="'.URL.'script/validate/jquery.validate.css" type="text/css"/>'."\n";
}
endif;

if ( !function_exists('fancybox') ) :
function fancybox(){
	echo '<script type="text/javascript" src="'.URL.'script/fancyapps/jquery.fancybox.js?v=2.1.4"></script>'."\n";
	echo '<link rel="stylesheet" type="text/css" href="'.URL.'script/fancyapps/jquery.fancybox.css?v=2.1.4" media="screen" />'."\n";
}
endif;

if ( !function_exists('jquery_ui') ) :
function jquery_ui($theme = "ui-lightness"){
	echo '<script src="'.URL.'script/jquery-ui/jquery-ui-custom.min.js" type="text/javascript"></script>'."\n";
	echo '<link href="'.URL.'script/jquery-ui/'.$theme.'/theme.css" rel="stylesheet" type="text/css">'."\n";
	echo '<script src="'.URL.'script/jquery-ui/jquery-ui-timepicker-addon.js" type="text/javascript"></script>'."\n";
	echo '<link href="'.URL.'script/jquery-ui/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css">'."\n";
}
endif;

if ( !function_exists('html5') ) :
function html5(){
	echo "<!--[if lt IE 9]>"."\n";
	echo "<script type='text/javascript' src='".URL."script/html5.js'></script>"."\n";
	echo "<![endif]-->"."\n";
}
endif;

if ( !function_exists('cufon') ) :
function cufon($font){
	echo '<script src="'.URL.'script/cufon/cufon-yui.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'font/'.$font.'.font.js" type="text/javascript"></script>'."\n";
}
endif;

if ( !function_exists('uploadify') ) :
function load_js($file = "function.js"){
	echo '<script type="text/javascript" src="'.URL.'script/'.$file.'"></script>'."\n";
}
endif;

if( !function_exists('carouFredSel') ) :
function carouFredSel(){
	echo '<script src="'.URL.'script/carouFredSel/jquery.carouFredSel-6.2.1-packed.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'script/carouFredSel/helper-plugins/jquery.mousewheel.min.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'script/carouFredSel/helper-plugins/jquery.touchSwipe.min.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'script/carouFredSel/helper-plugins/jquery.transit.min.js" type="text/javascript"></script>'."\n";
	echo '<script src="'.URL.'script/carouFredSel/helper-plugins/jquery.ba-throttle-debounce.min.js" type="text/javascript"></script>'."\n";
}
endif;

if( !function_exists('aw_showcase') ) :
function aw_showcase(){
	echo '<link rel="stylesheet" href="'.URL.'script/aw-showcase/css/style.css" />'."\n";
	echo '<script src="'.URL.'script/aw-showcase/jquery.aw-showcase.js" type="text/javascript"></script>'."\n";
}
endif;

if( !function_exists('marquee') ) :
function marquee(){
	echo '<script src="'.URL.'script/marquee/jquery.marquee.js" type="text/javascript"></script>'."\n";
}
endif;

if( !function_exists('uniform') ) :
function uniform($theme = "default"){
	echo '<link rel="stylesheet" href="'.URL.'script/uniform/themes/'.$theme.'/css/uniform.'.$theme.'.css" />'."\n";
	echo '<script src="'.URL.'script/uniform/jquery.uniform.min.js" type="text/javascript"></script>'."\n";
}
endif;

if( !function_exists('tooltip') ) :
function tooltip($theme = ""){
	echo '<link rel="stylesheet" type="text/css" href="'.URL.'script/tooltip/css/tooltipster.css" />'."\n";
	echo '<script type="text/javascript" src="'.URL.'script/tooltip/js/jquery.tooltipster.min.js"></script>'."\n";

	if($theme != ""){
		echo '<link rel="stylesheet" type="text/css" href="'.URL.'script/tooltip/css/tooltipster-'.$theme.'.css" />'."\n";
	}
}
endif;

if( !function_exists('intent') ) :
function intent(){
	echo '<script src="'.URL.'script/jquery.hoverIntent.js" type="text/javascript"></script>'."\n";
}
endif;

?>